<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>产品信息详情</title>
</head>
<script>

</script>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>详情查看</legend>
</fieldset>
    <form class="layui-form layui-form-pane" action="" id="form1">
        <input type="hidden" id="id" name="pi.id">
        <div class="layui-form-item">
            <label class="layui-form-label">产品名</label>
            <div class="layui-input-inline">
                <input type="text" name="pi.name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" id="name">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">定价</label>
            <div class="layui-input-inline">
                <input type="text" name="pi.price" lay-verify="required|number" placeholder="请输入" autocomplete="off" class="layui-input" id="price">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">时间</label>
            <div class="layui-input-inline">
                <input type="text" name="pi.time" placeholder="请输入" autocomplete="off" class="layui-input" id="time" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">规格名</label>
            <div class="layui-input-inline">
                <input type="text" name="ps.name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" id="psName">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">速别编号</label>
            <div class="layui-input-block">
                <select id="chain_typeId" name="pi.chain_typeId" class="select">
                    <option id="default"></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">节数</label>
            <div class="layui-input-inline">
                <input type="text" name="pi.sectionNum" lay-verify="required|number" placeholder="请输入" autocomplete="off" class="layui-input" id="sectionNum">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="pi.summary" id="summary"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn" lay-filter="save" lay-submit="">保存</button>
            <button class="layui-btn" lay-filter="back" type="button">返回</button>
        </div>
    </form>

</body>
<script>
    var id = parent.objdata1;
    layui.use(['laydate','upload','layer','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;

        //执行一个laydate实例
        laydate.render({
            elem: '#time' //指定元素
        });
        $.ajax({
            url:'/pi/get',
            type:'get',
            dataType:'json',
            success:function (data) {
                // console.log(data);
                $.each(data.data,function (index,value) {
                    // console.log(value);
                    $('#chain_typeId').append(new Option(value.ct.id,value.ct.id));

                });
                layui.form.render("select");
            }
        })
    });
    $.post(
        "/pi/query",{
            id:id,
            page:1,
            limit:10
        },function (res) {
            var obj = res.data;
            var code = res.code;
            var id = objdata1;
            var name = obj[0].pi.name;
            var price = obj[0].pi.price;
            var time = obj[0].pi.time;
            var psName = obj[0].ps.name;
            var chain_typeId = obj[0].pi.chain_typeId;
            ctid = chain_typeId;
            var sectionNum = obj[0].pi.sectionNum;
            var summary = obj[0].pi.summary;
            if (code == 0){
                $("#id").attr('value',id)
                $("#name").attr('value',name);
                $("#price").attr('value',price);
                $("#time").attr('value',time);
                $("#psName").attr('value',psName);
                $("#sectionNum").attr('value',sectionNum);
                $("#summary").attr("value",summary);
                $("#default").val(chain_typeId);
                $("#default").html(chain_typeId);
            }else {
                alert("未找到数据");
            }
        }
    );
    layui.form.on('submit(save)', function(data){
        $.post(
            "/pi/update", $("#form1").serialize(), function (res) {
                //判断
                if (res.code == 0){
                    toJumpGet($('.layui-body'),"/pages/pi/piList.html");
                } else {
                    layer.alert(res.msg);
                }
            }
        );
    });
    $(".layui-btn :eq(1)").on("click",function () {
        toJumpGet($('.layui-body'),"/pages/pi/piList.html");
    });
</script>
</html>